2020-2021 Sunseeker Telemetry and Lighting System
pmm_ex2_fastWakeUp.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //*****************************************************************************
70 //*****************************************************************************
71 
72 #include "driverlib.h"
73 
74 #define DUTY_CYCLE1 20
75 #define TIMER_PERIOD 40
76 
77 void main (void)
78 {
79  //Stop WDT
80  WDT_A_hold(WDT_A_BASE);
81 
82  //Set DCO FLL reference = REFO
83  UCS_initClockSignal(UCS_FLLREF,
84  UCS_REFOCLK_SELECT,
85  UCS_CLOCK_DIVIDER_1
86  );
87 
88  //Set ACLK = REFO
89  UCS_initClockSignal(UCS_ACLK,
90  UCS_REFOCLK_SELECT,
91  UCS_CLOCK_DIVIDER_1
92  );
93 
94  //~ 32*32768 = 1048576
95  UCS_initFLLSettle(1048,
96  32
97  );
98 
99  //SVS Low side is turned off
100  PMM_disableSvsL();
101 
102  //Monitor low side is turned off
103  PMM_disableSvmL();
104 
105  //Monitor high side is turned off
106  PMM_disableSvmH();
107 
108  //SVS High side is turned on
109  PMM_enableSvsH();
110 
111  //Enable POR on SVS Event
112  PMM_enableSvsHReset();
113 
114  //SVS high side Full perf mode,
115  PMM_enableSvsHInLPMFullPerf();
116 
117  //stays on in LPM3,enhanced protect
118  //Wait until high side, low side settled
119  while ( 0 == PMM_getInterruptStatus(
120  SVSMLDLYIFG + SVSMHDLYIFG )
121  ) ;
122 
123  PMM_clearPMMIFGS();
124 
125  //Clear P1.0 LED off
127  GPIO_PORT_P1,
128  GPIO_PIN0
129  );
130 
131  //Set P1.0 to output direction
132  GPIO_setAsOutputPin(
133  GPIO_PORT_P1,
134  GPIO_PIN0
135  );
136 
137  //P1.5 TA0.4 output 50% duty cycle
138  GPIO_setAsPeripheralModuleFunctionOutputPin(
139  GPIO_PORT_P1,
140  GPIO_PIN5
141  );
142 
143  //Start timer in upMode sourced by ACLK
144  Timer_A_initUpModeParam initUpParam = {0};
145  initUpParam.clockSource = TIMER_A_CLOCKSOURCE_ACLK;
146  initUpParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
147  initUpParam.timerPeriod = TIMER_PERIOD;
148  initUpParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE;
149  initUpParam.captureCompareInterruptEnable_CCR0_CCIE =
150  TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE;
151  initUpParam.timerClear = TIMER_A_DO_CLEAR;
152  initUpParam.startTimer = true;
153  Timer_A_initUpMode(TIMER_A0_BASE, &initUpParam);
154 
155 
156  //Generate PWM using capture
157  Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE,
158  TIMER_A_CAPTURECOMPARE_REGISTER_4
159  );
160 
161  Timer_A_initCompareModeParam initCompParam = {0};
162  initCompParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_4;
163  initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
164  initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_SET_RESET;
165  initCompParam.compareValue = DUTY_CYCLE1;
166  Timer_A_initCompareMode(TIMER_A0_BASE, &initCompParam);
167 
168  //Enter LPM3, enable interrupts
169  __bis_SR_register(LPM3_bits + GIE);
170 
171  //For debugger
172  __no_operation();
173 }
174 
175 //******************************************************************************
176 //
177 //This is the Timer0_A5 interrupt vector service routine.
178 //
179 //******************************************************************************
180 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
181 #pragma vector=TIMER0_A1_VECTOR
182 __interrupt
183 #elif defined(__GNUC__)
184 __attribute__((interrupt(TIMER0_A1_VECTOR)))
185 #endif
186 void TIMER0_A1_ISR (void)
187 {
188  switch (__even_in_range(TA0IV,14)){
189  case 0: break; //No interrupt
190  case 2: break; //CCR1 not used
191  case 4: break; //CCR2 not used
192  case 6: break; //reserved
193  case 8: break; //reserved
194  case 10: break; //reserved
195  case 12: break; //reserved
196  case 14: //overflow
197  //Toggle P1.0
198  GPIO_toggleOutputOnPin(
199  GPIO_PORT_P1,
200  GPIO_PIN0
201  );
202  break;
203  default: break;
204  }
205 }
206 
__no_operation()
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
void main(void)
#define DUTY_CYCLE1
#define TIMER_PERIOD
void TIMER0_A1_ISR(void)